import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

enum HintType { SUCCESS, WARNING, DANGER }

void showHint(String message, HintType type) {
  Future.microtask(
    () => Get.snackbar("", "",
        animationDuration: 300.milliseconds,
        padding: EdgeInsets.only(bottom: 20),
        messageText: Row(
          children: [
            SizedBox(
              width: 20,
            ),
            type == HintType.SUCCESS
                ? Icon(
                    Icons.check_circle,
                    color: Color.fromRGBO(113, 185, 69, 1),
                    size: 30,
                  )
                : (type == HintType.WARNING
                    ? Icon(
                        Icons.warning,
                        size: 30,
                        color: Color.fromRGBO(255, 195, 0, 1),
                      )
                    : Icon(
                        Icons.cancel,
                        size: 30,
                        color: Color.fromRGBO(254, 87, 88, 1),
                      )),
            SizedBox(
              width: 10,
            ),
            Expanded(
              child: Text(
                message,
                style: TextStyle(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                    fontSize: 22),
              ),
            )
          ],
        ),
        snackPosition: SnackPosition.TOP,
        maxWidth: 280,
        colorText: Colors.white,
        backgroundColor: Color.fromRGBO(36, 15, 81, 0.6),
        overlayColor: Color.fromRGBO(36, 15, 81, 1)),
  );
}

/// 弹出选择对话框
/// [title] 选择页面提示词
/// [option1] 第一个选项文本
/// [option2] 第二个选项文本
/// 返回 Future<int?> 选择结果的下标 (0: 第一个选项, 1: 第二个选项, null: 取消选择)
Future<int?> showSelectionDialog(
  String title,
  String option1,
  String option2,
) async {
  return await Get.dialog<int>(
    Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        width: 280,
        decoration: BoxDecoration(
          color: Color.fromRGBO(36, 15, 81, 0.95),
          borderRadius: BorderRadius.circular(20),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 标题
            Container(
              padding: EdgeInsets.all(20),
              child: Text(
                title,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
                textAlign: TextAlign.center,
              ),
            ),

            // 分隔线
            Divider(
              color: Colors.white.withOpacity(0.3),
              height: 1,
            ),

            // 选项1
            _buildOptionItem(option1, 0),

            // 分隔线
            Divider(
              color: Colors.white.withOpacity(0.3),
              height: 1,
            ),

            // 选项2
            _buildOptionItem(option2, 1),

            // 分隔线
            Divider(
              color: Colors.white.withOpacity(0.3),
              height: 1,
            ),
          ],
        ),
      ),
    ),
    barrierDismissible: true,
  );
}

/// 构建选项项目
Widget _buildOptionItem(String text, int index) {
  return Material(
    color: Colors.transparent,
    child: InkWell(
      onTap: () {
        Get.back(result: index); // 返回选择的下标
      },
      borderRadius: BorderRadius.zero,
      child: Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 16),
        child: Text(
          text,
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
          ),
          textAlign: TextAlign.center,
        ),
      ),
    ),
  );
}
